package y25.m2;

public class leetcode_11 {
    public int maxArea(int[] height) {
        int size = height.length;
        if(size == 2){
            return getH(height[1],height[0]);
        }
        int left =0;
        int right = size -1;
        int v = 0;
        while(left < right){
            int x = right - left;
            int newV = getH(height[left],height[right]) * x;
            v = v >= newV ? v : newV;
            if(height[left] > height[right]){
                right--;
            }else{
                left++;
            }
        }
        return v;
    }
    public int getH(int h1,int h2){
        return h1 > h2 ? h2 : h1;
    }
    public static void main(String[] args) {
        leetcode_11 leetcode_11 = new leetcode_11();
        System.out.println(leetcode_11.maxArea(new int[]{1,8,6,2,5,4,8,3,7}));
    }
}
